
import star from '../../assets/star.png'
import Phaser from 'phaser'
import dude from '../../assets/dude.png'

export default class ContainerScene extends Phaser.Scene {

    constructor() {
        super('containerScene')
    }

    // Initialization code here
    init(data) {
        console.log('--init--')
    }

    // Preload assets here
    preload() {
        console.log('--preload--')
        this.load.image('star', star);
        this.load.spritesheet('dude',
            dude,
            { frameWidth: 32, frameHeight: 48 }
        );
    }

    // 添加元素的方法
    // this.add.image(x, y, textureKey)
    // this.add.graphics() 动态绘制矩形、圆形、线条
    // this.add.sprite(x, y, textureKey) 添加可动画、交互的对象
    // this.add.text(x, y, content, style) 添加文字说明或数值显示
    // Create game objects and set up the scene here 
    create() {
        console.log('--create--')
        let starImg = this.add.image(200, 200, 'star')
        // this.cameras.main.setBackgroundColor(0x87ceeb);

        const container = this.add.container(0, 0);
     
        // 添加子对象
        container.add(this.add.rectangle(200,200,100,100,0xff0000));
        container.add(this.add.star(500,300,5,32,64,0xff0000));
        container.add(this.add.text(10, 50, '玩家名称',{color: "red"}));

        // 统一变换
        // container.setPosition(200, 200);
        // container.setRotation(Phaser.Math.DegToRad(45));
        // container.setScale(1.5);

        // 获取子对象
        const children = container.list; // 所有子对象数组
        console.log("子对象列表:", children)
        // 移除子对象
        // container.remove(children[0]);
    }




    // Update game logic each frame here
    update(time, delta) {
    }
}

class SelfSpriter extends Phaser.GameObjects.Sprite {



}

class SelfRect extends Phaser.GameObjects.Rectangle {



}